package com.neusoft.elmboot.util;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;

public class CommonUtil {

	public static String getCurrentDate() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Calendar calendar = Calendar.getInstance();
		return sdf.format(calendar.getTime());
	}

	public static String addMinutes(String time, int minutes) {
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
		LocalDateTime dateTime = LocalDateTime.parse(time, formatter);
		LocalDateTime result = dateTime.plusMinutes(minutes);
		return result.format(formatter);
	}

	public static String subtractMinutes(String time, int minutes) {
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
		LocalDateTime dateTime = LocalDateTime.parse(time, formatter);
		LocalDateTime result = dateTime.minusMinutes(minutes);
		return result.format(formatter);
	}
}
